# -*- encoding=utf8 -*-

__author__ = "Bryan.Chen"
__desc__ = ""

from airtest.core.api import *

auto_setup(__file__)

from poco.drivers.std import StdPoco
poco = StdPoco()

using("../FlowTest.air")
import FlowTest


class Club_Flow(FlowTest.BaseTestCase):
    def __init__(self):
        print("%s __init__" % (__file__))

    def runTest(self, args):
        print("%s runTest" % (__file__))

        clubName = "AT_"
        if "clubName" in args:
            clubName = args["clubName"]

        clubHomePageLayer = poco("ClubHomePageLayer")

        if not clubHomePageLayer.exists():
            return False

        myCreateList = clubHomePageLayer.offspring("my_create_list")
        clubItems = myCreateList.offspring("my_create_item")
        for i in range(0, len(clubItems)):
            txtName = clubItems[i].offspring("club_name").get_text()
            if txtName.startswith(clubName):
                self.clickButton(clubItems[i])
                break

        clubPageLayer = poco("ClubPageLayer")

        btnMenu = clubPageLayer.offspring("btn_pulldown")
        self.clickButton(btnMenu)

        btnRoomFlow = clubPageLayer.offspring("btn_room_flow")
        self.clickButton(btnRoomFlow)

        clubRecordLayer = clubPageLayer.offspring("ClubFlowLayer")
        if not clubRecordLayer.exists():
            return False

        btnBack = clubRecordLayer.offspring("back_btn")
        self.clickButton(btnBack)

        btnBack = clubPageLayer.offspring("back_btn")
        self.clickButton(btnBack)

        return True

_instance = Club_Flow()
runTest = _instance.runTest
